#include<iostream>
#include<cstdio>
#include<vector>
#define N 600000
#define M 3000
#define inf 1e9
using namespace std;
int read()
{
    char c=0;
    int sum=0,f=1;
    while (c!='-'&&(c<'0'||c>'9')) c=getchar();
    if (c=='-') c=getchar(),f=-1;
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum*f;
}
long long gcd(long long a,long long b)
{
    if (!b) return a;
    return gcd(b,a%b);
}
struct reads
{
    int l,r,num;
};
struct rds
{
    long long a;
    int b;
    bool operator < (const rds &t)const
	{
		return a*t.b<b*t.a;    
	}
};
rds ans[N+1],A[N+1],B[N+1],st[M+1][M+1];
int n,m,a[N+1],s[N+1],dque[N+1],top,dque2[N+1],top2,tong[N+1],length,tong2[N+1],length2,ps[N+1],ps2[N+1];
void solve(int l,int r,vector<reads>p)
{
    if (l==r||p.empty()) return;
    int mid=(l+r)>>1,minn=inf,maxn=-inf;
    vector<reads>tA;
    vector<reads>tB;
    length=length2=top=top2=0,A[mid+1]=(rds){-1,0},B[mid]=(rds){-1,0};
    for (int i=mid;i>=l;--i)
    {
		A[i]=A[i+1];
		while (top&&s[dque[top]]<=s[i]) top--;
		while (top2&&s[dque2[top2]]>=s[i]) top2--;
		for (int j=1;j<=top;++j) A[i]=max(A[i],(rds){1ll*(s[i]-s[dque[j]])*(s[i]-s[dque[j]]),dque[j]-i});
		for (int j=1;j<=top2;++j) A[i]=max(A[i],(rds){1ll*(s[i]-s[dque2[j]])*(s[i]-s[dque2[j]]),dque2[j]-i});
		dque[++top]=i,dque2[++top2]=i;
    }
    top=top2=0;
    for (int i=mid+1;i<=r;++i)
    {
		B[i]=B[i-1];
		while (top&&s[dque[top]]<=s[i]) top--;
		while (top2&&s[dque2[top2]]>=s[i]) top2--;
		for (int j=1;j<=top;++j) B[i]=max(B[i],(rds){1ll*(s[i]-s[dque[j]])*(s[i]-s[dque[j]]),i-dque[j]});
		for (int j=1;j<=top2;++j) B[i]=max(B[i],(rds){1ll*(s[i]-s[dque2[j]])*(s[i]-s[dque2[j]]),i-dque2[j]});
		dque[++top]=i,dque2[++top2]=i;
    }
    for (int i=mid;i>=l;--i)
    {
		if (s[i]<minn) minn=s[i],tong[++length]=i;
		if (s[i]>maxn) maxn=s[i],tong[++length]=i;
		ps[i]=length;
    }
    minn=inf,maxn=-inf;
    for (int i=mid+1;i<=r;++i)
    {
		if (s[i]<minn) minn=s[i],tong2[++length2]=i;
		if (s[i]>maxn) maxn=s[i],tong2[++length2]=i;
		ps2[i]=length2;
    }
    for (int i=1;i<=length;++i)
		for (int j=1;j<=length2;++j)
		{
			st[i][j]=(rds){1ll*(s[tong2[j]]-s[tong[i]])*(s[tong2[j]]-s[tong[i]]),tong2[j]-tong[i]};
			if (i-1>=1) st[i][j]=max(st[i][j],st[i-1][j]);
			if (j-1>=1) st[i][j]=max(st[i][j],st[i][j-1]);
		}
    for (int i=0;i<p.size();++i)
    {
		if (p[i].r<=mid) tA.push_back(p[i]);
		else if (p[i].l>=mid+1) tB.push_back(p[i]);
		else ans[p[i].num]=max(max(A[p[i].l],B[p[i].r]),st[ps[p[i].l]][ps2[p[i].r]]);
    }
    solve(l,mid,tA),solve(mid+1,r,tB);
    return;
}
int main()
{
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
    int l,r;
    vector<reads>p;
    n=read();
    for (int i=1;i<=n;++i) a[i]=read(),s[i]=s[i-1]+a[i];
    m=read();
    for (int i=1;i<=m;++i) l=read(),r=read(),p.push_back((reads){l-1,r,i});
    solve(0,n,p);
    for (int i=1;i<=m;++i) printf("%lld %lld\n",ans[i].a/gcd(ans[i].a,ans[i].b),ans[i].b/gcd(ans[i].a,ans[i].b));
    return 0;
}
